local cjson = require "cjson"
local currentTime = os.date("%Y-%m-%d %H:%M:%S", os.time())


local key = "logs"

--local len,err = ngx.shared.logs:rpush(key, myparams)
local remote_addr = ngx.req.get_headers()["X-Real-IP"]
if remote_addr == nil then
     remote_addr = ngx.req.get_headers()["x_forwarded_for"]
end
if remote_addr == nil then
     remote_addr = ngx.var.remote_addr
end
local jsonMessage = {}
jsonMessage.currentTime=currentTime or ''
jsonMessage.remote_addr=remote_addr or ''
jsonMessage.upstream_addr=ngx.var.upstream_addr or ''
jsonMessage.currentTime=currentTime
jsonMessage.request_time=ngx.var.request_time or -100
jsonMessage.upstream_response_time=ngx.var.upstream_response_time or -100
jsonMessage.body_bytes_sent=ngx.var.body_bytes_sent or -100
jsonMessage.status=ngx.var.status or 0
jsonMessage.req_req=ngx.var.uri or ''


jsonMessage.req_body=ngx.var.request_body
ngx.shared.logs:rpush(key, cjson.encode(jsonMessage))
--ngx.log(ngx.ERR,"=======log_by_lua===="..cjson.encode(jsonMessage))
if err then

     ngx.log(ngx.ERR,"failed to put log vals into shared dict")

     return

end

